package com.${ltdAbbr}.xiao.${module}.task.job;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

import com.yt.xiao.commons.util.TraceIDUtils;

/**
 * 基础job
 * @author admin
 *
 */
public abstract class AbstractBaseJob {

    /**
     * 日志
     */
    private static final Logger logger = LoggerFactory.getLogger(AbstractBaseJob.class);

    /**
     * job入口
     */
    public void run(){
        final String jobClassName = "job["+this.getClass()+"]";
        try {
            TraceIDUtils.continueTraceID();
        } catch (Exception e2) {
            logger.error("设置追踪id异常:"+e2.getMessage(), e2);
        }
        logger.info(jobClassName+":开始执行");
        try{
            this.doWork();
            logger.info(jobClassName+":执行完成");
        }catch(Exception e){
            logger.error(jobClassName+":执行失败,参考信息"+e.getMessage(), e);
        }
        try {
            MDC.clear();
        } catch (Exception e1) {
            logger.error("清理追踪id异常:"+e1.getMessage(), e1);
        }
    }

    /**
     * 实现此方法
     */
    public abstract void doWork();
}
